﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using HIWSystem.Common;
using HIWSystem.Helpers;
using HIWSystem.Models;

namespace HIWSystem.ViewModel
{
    public class StatisticsStationOutputViewModel :ViewModelBase
    {
        #region 属性
        DataTable dtDetails = new DataTable();
        DataTable dtStationOutput = new DataTable();
        TrackingCombineSnEntity entity = null;
        private bool IsFirstFilter = true;
        private bool isFirstFilterStation = true;
        ObservableCollection<PartNumberEntity> backupPNs = null;
        ObservableCollection<StationsEntity> backupStations = null;
        private string pn="无";
        /// <summary>
        /// 机种信息
        /// </summary>
        public string PN
        {
            get { return pn; }
            set { pn = value; this.RaisePropertyChanged(() => PN); }
        }
        private string searchPNText;
        /// <summary>
        /// ComboBox文本框输入的搜索文本
        /// </summary>
        public string SearchPNText
        {
            get { return searchPNText; }
            set { searchPNText = value; this.RaisePropertyChanged(() => SearchPNText); }
        }
        private PartNumberEntity selectedPartNumber;
        /// <summary>
        ///  选中的机种
        /// </summary>
        public PartNumberEntity SelectedPartNumber
        {
            get { return selectedPartNumber; }
            set { selectedPartNumber = value; this.RaisePropertyChanged(() => SelectedPartNumber); }
        }

        private ObservableCollection<PartNumberEntity> pns;
        /// <summary>
        /// 机种信息
        /// </summary>
        public ObservableCollection<PartNumberEntity> PNs
        {
            get { return pns; }
            set { pns = value; this.RaisePropertyChanged(() => PNs); }
        }
        private string selectedPN;
        /// <summary>
        /// 选中的机种
        /// </summary>
        public string SelectedPN
        {
            get { return selectedPN; }
            set { selectedPN = value; this.RaisePropertyChanged(() => SelectedPN); }
        }
        private ObservableCollection<TrackingEntity> sequences;
        /// <summary>
        /// 测序集合
        /// </summary>
        public ObservableCollection<TrackingEntity> Sequences
        {
            get { return sequences; }
            set { sequences = value; this.RaisePropertyChanged(() => Sequences); }
        }
        private TrackingEntity selectedSequence;
        /// <summary>
        /// 选择的测试项
        /// </summary>
        public TrackingEntity SelectedSequence
        {
            get { return selectedSequence; }
            set { selectedSequence = value; this.RaisePropertyChanged(() => SelectedSequence); }
        }
        private string sequence;
        /// <summary>
        /// 选择的测序值
        /// </summary>
        public string Sequence
        {
            get { return sequence; }
            set { sequence = value; this.RaisePropertyChanged(() => Sequence); }
        }
        private string startTime;
        /// <summary>
        /// 开始时间
        /// </summary>
        public string StartTime
        {
            get { return startTime; }
            set { startTime = value; this.RaisePropertyChanged(() => StartTime); }
        }
        private string stopTime;
        /// <summary>
        /// 结束时间
        /// </summary>
        public string StopTime
        {
            get { return stopTime; }
            set { stopTime = value; this.RaisePropertyChanged(() => StopTime); }
        }
        private bool isEnabledQueryButton = true;
        /// <summary>
        /// 是否启用查询按钮
        /// </summary>
        public bool IsEnabledQueryButton
        {
            get { return isEnabledQueryButton; }
            set { isEnabledQueryButton = value; this.RaisePropertyChanged(() => IsEnabledQueryButton); }
        }
        private Visibility isVisibleLoading = Visibility.Collapsed;
        /// <summary>
        /// 是否显示加载图标
        /// </summary>
        public Visibility IsVisibleLoading
        {
            get { return isVisibleLoading; }
            set { isVisibleLoading = value; this.RaisePropertyChanged(() => IsVisibleLoading); }
        }
        private ObservableCollection<StationOutputEntity> stationOutputs;
        /// <summary>
        /// 站位产量汇总数据集
        /// </summary>
        public ObservableCollection<StationOutputEntity> StationOutputs
        {
            get { return stationOutputs; }
            set { stationOutputs = value; this.RaisePropertyChanged(() => StationOutputs); }
        }
        private ObservableCollection<TrackingCombineSnEntity> details;
        /// <summary>
        /// 站位产量详细数据集
        /// </summary>
        public ObservableCollection<TrackingCombineSnEntity> Details
        {
            get { return details; }
            set { details = value; this.RaisePropertyChanged(() => Details); }
        }
        private bool isEnabledExportButton=true;
        /// <summary>
        /// 是否启用导出按钮
        /// </summary>
        public bool IsEnabledExportButton
        {
            get { return isEnabledExportButton; }
            set { isEnabledExportButton=value; this.RaisePropertyChanged(() => IsEnabledExportButton); }
        }
        private bool comboPNOpen;
        /// <summary>
        /// 是否打开机种下拉列表框
        /// </summary>
        public bool ComboPNOpen
        {
            get { return comboPNOpen; }
            set { comboPNOpen = value; this.RaisePropertyChanged(() => ComboPNOpen); }
        }
        private ObservableCollection<StationsEntity> stations;
        /// <summary>
        /// 站位信息
        /// </summary>
        public ObservableCollection<StationsEntity> Stations
        {
            get { return stations; }
            set { stations = value; this.RaisePropertyChanged(() => Stations); }
        }
        private string selectedStation;
        /// <summary>
        /// 选择的站位
        /// </summary>
        public string SelectedStation
        {
            get { return selectedStation; }
            set { selectedStation = value; this.RaisePropertyChanged(() => SelectedStation); }
        }
        private string station="无";
        /// <summary>
        /// 站位
        /// </summary>
        public string Station
        {
            get { return station; }
            set { station = value; this.RaisePropertyChanged(() => Station); }
        }
        private bool isOpenComboStationDropDown=false;
        /// <summary>
        /// 是否展开站位下拉列表框
        /// </summary>
        public bool IsOpenComboStationDropDown
        {
            get { return isOpenComboStationDropDown; }
            set { isOpenComboStationDropDown = value; this.RaisePropertyChanged(() => IsOpenComboStationDropDown); }
        }
        private string searchStationText;
        /// <summary>
        ///  站位下拉列表框搜索的文本
        /// </summary>
        public string SearchStationText
        {
            get { return searchStationText; }
            set { searchStationText = value; this.RaisePropertyChanged(() => SearchStationText); }
        }
        #endregion

        #region 命令
        private RelayCommand loadedPageCmd;
        /// <summary>
        /// 页面加载命令
        /// </summary>
        public RelayCommand LoadedPageCmd
        {
            get 
            {
                if (loadedPageCmd==null)
                {
                    LoadedPageCmd = new RelayCommand(LoadedPage);
                }
                return loadedPageCmd; 
            }
            set { loadedPageCmd = value; }
        }
        private RelayCommand queryCmd;
        /// <summary>
        /// 查询命令
        /// </summary>
        public RelayCommand QueryCmd
        {
            get
            {
                if (queryCmd == null)
                {
                    queryCmd = new RelayCommand(QueryStationOutputAsync);
                }
                return queryCmd;
            }
            set { queryCmd = value; }
        }
        private RelayCommand<StationOutputEntity> showStationOutputDetatilsCmd;

        public RelayCommand<StationOutputEntity> ShowStationOutputDetatilsCmd
        {
            get {
                if (showStationOutputDetatilsCmd==null)
                {
                    showStationOutputDetatilsCmd = new RelayCommand<StationOutputEntity>(ShowStationOutputDetailsAsync);
                }
                return showStationOutputDetatilsCmd; }
            set { showStationOutputDetatilsCmd = value; }
        }
        private RelayCommand exportCmd;

        public RelayCommand ExportCmd
        {
            get {
                exportCmd = exportCmd ?? new RelayCommand(ExportAsync);
                return exportCmd; }
            set { exportCmd = value; }
        }
        private RelayCommand filterPNCmd;

        public RelayCommand FilterPNCmd
        {
            get {
                filterPNCmd = filterPNCmd ?? new RelayCommand(FilterPN);
                return filterPNCmd; }
            set { filterPNCmd = value; }
        }
        //private RelayCommand<string> comboPN_SelectionChangedCmd;

        //public RelayCommand<string> ComboPN_SelectionChangedCmd
        //{
        //    get
        //    {
        //        if (comboPN_SelectionChangedCmd == null)
        //        {
        //            comboPN_SelectionChangedCmd = new RelayCommand<string>(ComboPN_SelectionChangedHandler);
        //        }
        //        return comboPN_SelectionChangedCmd;
        //    }
        //    set { comboPN_SelectionChangedCmd = value; }
        //}
        private RelayCommand filterStationCmd;

        public RelayCommand FilterStationCmd
        {
            get
            {
                if (filterStationCmd == null)
                {
                    filterStationCmd = new RelayCommand(FilterStation);
                }
                return filterStationCmd;
            }
            set { filterStationCmd = value; }
        }
        #endregion

        #region 方法
        /// <summary>
        /// 页面加载
        /// </summary>
        private void LoadedPage()
        {
            Sequences = new ObservableCollection<TrackingEntity>();
            Sequences.Add(new TrackingEntity { TestSequence = "全部" });
            Sequences.Add(new TrackingEntity { TestSequence = "首次" });
            Sequences.Add(new TrackingEntity { TestSequence = "最后一次" });
            //填充机种信息到下拉列表框中
            FillPNsToComboBox();
            //填充站位信息到下拉列表框中
            FillStationsToComboBox();
        }
        /// <summary>
        /// 查询站位产量《异步》
        /// </summary>
        private async void QueryStationOutputAsync()
        {
            string retMsg = string.Empty;
            string[] arrMsg = new string[] { };

            ObservableCollection<StationOutputEntity> tmpStationOutputs = new ObservableCollection<StationOutputEntity>();
            try
            {
                await Task.Run(() =>
                {
                    Application.Current.Dispatcher.BeginInvoke((Action)(() => {
                        //禁用查询按钮
                        this.IsEnabledQueryButton = false;
                        //显示加载图标
                        this.IsVisibleLoading = Visibility.Visible;
                        StationOutputs = new ObservableCollection<StationOutputEntity>();
                    }));
                    string sequ = string.Empty;
                    switch (this.Sequence)
                    {
                        case "全部":
                            sequ = "*";
                            break;
                        case "首次":
                            sequ = "1";
                            break;
                        case "最后一次":
                            sequ = "2";
                            break;
                        default:
                            sequ = "*";
                            break;
                    }
                    entity = new TrackingCombineSnEntity
                    {
                        PN =this.PN=="无"?"": this.PN ?? "",
                        Station =this.Station=="无"?"":this.Station ?? "",
                        StartTime = this.StartTime ?? "",
                        StopTime = this.StopTime ?? "",
                        TestSequence = sequ,
                    };
                    dtStationOutput = new DataTable();
                    retMsg = BusinessProcess.StatisticsStationOutputs(entity, out dtStationOutput);
                    arrMsg = retMsg.Split('|');
                    if (arrMsg[0] == "Y")
                    {
                        for (int i = 0; i < dtStationOutput.Rows.Count; i++)
                        {
                            tmpStationOutputs.Add(new StationOutputEntity
                            {
                                PN = dtStationOutput.Rows[i]["PN"].ToString() ?? "",
                                Station = dtStationOutput.Rows[i]["Station"].ToString() ?? "",
                                Pass = dtStationOutput.Rows[i]["Pass"].ToString() ?? "",
                                Fail = dtStationOutput.Rows[i]["Fail"].ToString() ?? "",
                                Total = dtStationOutput.Rows[i]["Total"].ToString() ?? "",
                                Yield=dtStationOutput.Rows[i]["Yield"].ToString()??""
                            });
                        }
                        Application.Current.Dispatcher.BeginInvoke((Action)(() => {
                            this.StationOutputs = tmpStationOutputs;
                        }));
                    }
                    else
                    {
                        MessageBox.Show(arrMsg[1], "软件温馨提示", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                    Application.Current.Dispatcher.BeginInvoke((Action)(() => {
                        this.IsVisibleLoading = Visibility.Collapsed;//隐藏加载动画
                        this.IsEnabledQueryButton = true;
                    }));

                });
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(string.Format("执行方法【{0}】出现错误【{1}】", nameof(QueryStationOutputAsync), ex.Message), ex);
                throw new Exception(ex.Message);
            }
        }

        private async void ShowStationOutputDetailsAsync(StationOutputEntity obj)
        {
            if (obj!=null)
            {
                string retMsg = string.Empty;
                string[] arrMsg = new string[] { };
                try
                {
                    
                    dtDetails = new DataTable();
                    Details = new ObservableCollection<TrackingCombineSnEntity>();
                    ObservableCollection<TrackingCombineSnEntity> tmpDetails = new ObservableCollection<TrackingCombineSnEntity>();
                    TrackingCombineSnEntity tmpEntity = new TrackingCombineSnEntity
                    {
                        PN = obj.PN ?? "",
                        Station = obj.Station ?? "",
                        StartTime = entity.StartTime ?? "",
                        StopTime = entity.StopTime ?? "",
                        TestSequence = entity.TestSequence ?? "*"
                    };
                    //开始多线程
                    await Task.Run(() => {
                        Application.Current.Dispatcher.BeginInvoke((Action)(() => {
                            this.IsVisibleLoading = Visibility.Visible;
                        }));
                       retMsg= BusinessProcess.StatisticsStationOutputDetails(tmpEntity, out dtDetails);
                        arrMsg = retMsg.Split('|');
                        if (arrMsg[0] == "Y")
                        {
                            for (int i = 0; i < dtDetails.Rows.Count; i++)
                            {
                                tmpDetails.Add(new TrackingCombineSnEntity
                                {
                                    Sn = dtDetails.Rows[i]["Sn"].ToString() ?? "",
                                    WO = dtDetails.Rows[i]["WO"].ToString() ?? "",
                                    Station = dtDetails.Rows[i]["Station"].ToString() ?? "",
                                    Result = dtDetails.Rows[i]["Result"].ToString() ?? "",
                                    FailDescription = dtDetails.Rows[i]["FailDescription"].ToString() ?? "",
                                    FailValue = dtDetails.Rows[i]["FailValue"].ToString() ?? "",
                                    EquipmentName = dtDetails.Rows[i]["EquipmentName"].ToString() ?? "",
                                    TestSequence = dtDetails.Rows[i]["TestSequence"].ToString() ?? "",
                                    StartTime = dtDetails.Rows[i]["StartTime"].ToString() ?? "",
                                    StopTime = dtDetails.Rows[i]["StopTime"].ToString() ?? "",
                                    Duration = dtDetails.Rows[i]["Duration"].ToString() ?? "",
                                    Shift = dtDetails.Rows[i]["Shift"].ToString() ?? "",
                                    Actor = dtDetails.Rows[i]["Actor"].ToString() ?? "",
                                    CreateAt = dtDetails.Rows[i]["CreateAt"].ToString() ?? "",
                                });
                            }
                            Application.Current.Dispatcher.BeginInvoke((Action)(() => {
                                this.Details = tmpDetails;
                            }));
                        }
                        else
                        {
                            MessageBox.Show(arrMsg[1], "软件温馨提示", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                        Application.Current.Dispatcher.BeginInvoke((Action)(() => {
                            this.IsVisibleLoading = Visibility.Collapsed;//隐藏加载动画
                        }));
                    });
                }
                catch (Exception ex)
                {
                    LogHelper.WriteLog(string.Format("执行方法【{0}】出现错误【{1}】", nameof(ShowStationOutputDetailsAsync), ex.Message), ex);
                    throw new Exception(ex.Message);
                }
            }
        }
        /// <summary>
        /// 导出报表
        /// </summary>
        private async void ExportAsync()
        {
            if (dtStationOutput.Rows.Count==0 && dtDetails.Rows.Count==0)
            {
                MessageBox.Show("没有数据需要导出","软件温馨提示!",MessageBoxButton.OK,MessageBoxImage.Warning);
                return;
            }
            if (IsEnabledQueryButton==false)
            {
                MessageBox.Show("正在查询数据...待查询完再导出", "软件温馨提示!", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }
            //保存数据之前先关闭Excel
            BusinessProcess.KillProcess("EXCEL");
            this.IsEnabledExportButton = false;
            //创建Excel  
            Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
            Microsoft.Office.Interop.Excel.Workbook excelWB = excelApp.Workbooks.Add(System.Type.Missing);    //创建工作簿（WorkBook：即Excel文件主体本身）  
            Microsoft.Office.Interop.Excel.Worksheet excelWS = (Microsoft.Office.Interop.Excel.Worksheet)excelWB.Worksheets[1];   //创建工作表（即Excel里的子表sheet） 1表示在子表sheet1里进行数据导出  
            //excelWS.Cells.NumberFormat = "@";     //  如果数据中存在数字类型 可以让它变文本格式显示  
            //将数据导入到工作表的单元格
            await Task.Run(() => {
                //显示加载动画
                this.IsVisibleLoading = Visibility.Visible;
                for (int i = 0; i < dtStationOutput.Columns.Count; i++)
                {
                    excelWS.Cells[1, i + 1] = dtStationOutput.Columns[i].ColumnName;
                }

                for (int i = 0; i < dtStationOutput.Rows.Count; i++)
                {
                    for (int j = 0; j < dtStationOutput.Columns.Count; j++)
                    {
                        excelWS.Cells[i + 2, j + 1] = dtStationOutput.Rows[i][j].ToString();   //Excel单元格第一个从索引1开始 
                    }
                }
                //创建工作表（Worksheet：工作表，即Excel里的子表sheet）
                excelWS = (Microsoft.Office.Interop.Excel.Worksheet)excelWB.Worksheets.Add(System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value);
                //设置表名
                excelWS.Name = "Details";
                //将数据导入到工作表的单元格
                for (int i = 0; i < dtDetails.Columns.Count; i++)
                {
                    excelWS.Cells[1, i + 1] = dtDetails.Columns[i].ColumnName;
                }

                for (int i = 0; i < dtDetails.Rows.Count; i++)
                {
                    for (int j = 0; j < dtDetails.Columns.Count; j++)
                    {
                        excelWS.Cells[i + 2, j + 1] = dtDetails.Rows[i][j].ToString();   //Excel单元格第一个从索引1开始 
                    }
                }
                //关闭加载动画
                this.IsVisibleLoading = Visibility.Collapsed;
            });

            //使用对话框让用户选择保存位置和填写保存的文件名
            Microsoft.Win32.SaveFileDialog sfd = new Microsoft.Win32.SaveFileDialog();

            sfd.Filter = "Excel工作簿(*.xlsx)|*.xlsx";

            sfd.FilterIndex = 1;

            sfd.RestoreDirectory = true;

            if (sfd.ShowDialog() == true)
            {
                string localFilePath = sfd.FileName.ToString(); //获得文件路径
                string fileNameExt = localFilePath.Substring(localFilePath.LastIndexOf("\\") + 1); //获取文件名，不带路径

                //获取文件路径，不带文件名
                //FilePath = localFilePath.Substring(0, localFilePath.LastIndexOf("\\"));
                //给文件名前加上时间
                //newFileName = DateTime.Now.ToString("yyyyMMdd") + fileNameExt;
                //在文件名里加字符
                //saveFileDialog1.FileName.Insert(1,"dameng");
                //System.IO.FileStream fs = (System.IO.FileStream)sfd.OpenFile();//输出文件fs输出带文字或图片的文件，就看需求了
                excelWB.SaveAs(localFilePath);  //将其进行保存到指定的路径  
                excelWB.Close();
                excelApp.Quit();  //KillAllExcel(excelApp); 释放可能还没释放的进程
                MessageBox.Show("导出表格成功!");
                System.Diagnostics.Process.Start(localFilePath);//保存完成后  打开文件
            }
            this.IsEnabledExportButton = true;
        }
        /// <summary>
        /// 填充机种信息
        /// </summary>
        private void FillPNsToComboBox()
        {
            #region 验证使用
            //PNs = new ObservableCollection<PartNumberEntity>();
            //PNs.Add(new PartNumberEntity { PN = "TEST1-AAA" });
            //PNs.Add(new PartNumberEntity { PN = "MEST1-AAA" });
            //PNs.Add(new PartNumberEntity { PN = "SEST1-AAA" });
            //PNs.Add(new PartNumberEntity { PN = "REST1-AAA" });
            //PNs.Add(new PartNumberEntity { PN = "BEST1-AAA" });
            //PNs.Add(new PartNumberEntity { PN = "TEST1-AAA" });
            //PNs.Add(new PartNumberEntity { PN = "AEST1-AAA" });
            //PNs.Add(new PartNumberEntity { PN = "TEST1-AAA" });
            //PNs.Add(new PartNumberEntity { PN = "OEST1-AAA" });
            //PNs.Add(new PartNumberEntity { PN = "TEST1-AAA" });
            //PNs.Add(new PartNumberEntity { PN = "TEST1-AAA" });
            //PNs.Add(new PartNumberEntity { PN = "NEST1-AAA" });
            //PNs.Add(new PartNumberEntity { PN = "TEST1-AAA" });
            //PNs.Add(new PartNumberEntity { PN = "MEST1-AAA" });
            //PNs.Add(new PartNumberEntity { PN = "TEST1-AAA" });
            //PNs.Add(new PartNumberEntity { PN = "REST1-AAA" });
            //PNs.Add(new PartNumberEntity { PN = "TEST1-AAA" });
            //PNs.Add(new PartNumberEntity { PN = "WEST1-AAA" });
            //PNs.Add(new PartNumberEntity { PN = "XEST1-AAA" });
            #endregion
            DataTable dtPNs = new DataTable();
            dtPNs = BusinessProcess.GetPNs(EnumPNType.All);
            PNs = new ObservableCollection<PartNumberEntity>();
            PNs.Add(new PartNumberEntity { PN = "无" });
            for (int i = 0; i < dtPNs.Rows.Count; i++)
            {
                PNs.Add(new PartNumberEntity
                {
                    PN = dtPNs.Rows[i]["PartNumber"].ToString()
                });
            }
        }
        /// <summary>
        /// 填充机种信息
        /// </summary>
        private void FillStationsToComboBox()
        {
            DataTable dtStations = new DataTable();
            dtStations = BusinessProcess.GetStations(EnumStationType.All);
            Stations = new ObservableCollection<StationsEntity>();
            Stations.Add(new StationsEntity { Station = "无" });
            for (int i = 0; i < dtStations.Rows.Count; i++)
            {
                Stations.Add(new StationsEntity
                {
                    Station = dtStations.Rows[i]["Station"].ToString()
                });
            }
        }
        protected void FilterPN()
        {
            ComboPNOpen = true;
            //当是第一次过滤的时候备份原始数据
            //这样是为了当不输入搜索条件时添加原始数据到列表中
            //当输入搜索条件时生成过滤集合绑定当下拉列表中
            if (IsFirstFilter)
            {
                backupPNs = new ObservableCollection<PartNumberEntity>();
                backupPNs = PNs;
                IsFirstFilter = false;
            }
            //backupPNs = PNs;
            if (!string.IsNullOrEmpty(SearchPNText))
            {
                IEnumerable<PartNumberEntity> partNumberEntities = PNs.Where(s => s.PN.ToUpper().Contains(SearchPNText.ToUpper()));
                PNs = new ObservableCollection<PartNumberEntity>();
                foreach (var p in partNumberEntities)
                {
                    PNs.Add(p);
                }
            }
            else
            {
                PNs = backupPNs;
            }
            //OnPropertyChanged("Shops");
        }
        /// <summary>
        /// 筛选站位下拉列表框中的数据
        /// </summary>
        private void FilterStation()
        {
            IsOpenComboStationDropDown = true;
            //当是第一次过滤的时候备份原始数据
            //这样是为了当不输入搜索条件时添加原始数据到列表中
            //当输入搜索条件时生成过滤集合绑定当下拉列表中
            if (isFirstFilterStation)
            {
                backupStations = new ObservableCollection<StationsEntity>();
                backupStations = Stations;
                isFirstFilterStation = false;
            }
            if (!string.IsNullOrEmpty(SearchStationText) && Stations != null)
            {
                IEnumerable<StationsEntity> stations = Stations.Where(s => s.Station.ToUpper().Contains(SearchStationText.ToUpper()));
                Stations = new ObservableCollection<StationsEntity>();
                foreach (var s in stations)
                {
                    Stations.Add(s);
                }
            }
            else
            {
                Stations = backupStations;
            }

        }
        /// <summary>
        /// 机种下拉框选项改变事件处理函数
        /// </summary>
        //private void ComboPN_SelectionChangedHandler(string param)
        //{
        //    if (param == null)
        //    {
        //        return;
        //    }
        //    DataTable dtStations = new DataTable();
        //    dtStations = BusinessProcess.GetStationsByPN(param);
        //    Stations = new ObservableCollection<StationsEntity>();
        //    for (int i = 0; i < dtStations.Rows.Count; i++)
        //    {
        //        Stations.Add(new StationsEntity { Station = dtStations.Rows[i]["Station"].ToString() });
        //    }
        //}
        #endregion
    }
}
